package org.libarae.communication;

import static org.libarae.communication.HTTPUtils.postGetAddress;

import org.libarae.communication.request.BookInfoRequest;
import org.libarae.communication.request.BookSearchRequest;
import org.libarae.communication.request.FeaturedTabRequest;
import org.libarae.communication.request.GetThreadMessagesRequest;
import org.libarae.communication.request.LoginRequest;
import org.libarae.communication.request.LogoutRequest;
import org.libarae.communication.request.MailboxMessagesRequest;
import org.libarae.communication.request.PictureRequest;
import org.libarae.communication.request.Request;

public class GETMessageHandler 
{
	
	public static Request parseGET(String httpMessage)
	{
		String destition = postGetAddress(httpMessage);
		
		System.out.println(destition + " was requested");
		Request rq = null;
		
		if(destition.startsWith("/login.html"))
			rq = new LoginRequest();
		else if(destition.startsWith("/search.html"))
			rq = new BookSearchRequest();
		else if(destition.startsWith("/messages.html"))
			rq = new MailboxMessagesRequest();
		else if(destition.startsWith("/bookInfo.html"))
			rq = new BookInfoRequest();
		else if(destition.startsWith("/featured.html"))
			rq = new FeaturedTabRequest();
		else if(destition.startsWith("/image"))
			rq = new PictureRequest();
		else if(destition.startsWith("/logout.html"))
			rq = new LogoutRequest();
		else if(destition.startsWith("/message.html"))
			rq = new GetThreadMessagesRequest();
	
		if(rq != null)
			rq.decodeGET(httpMessage);
		
		return rq;
	}
}
